﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ecdl.demo.model.file;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

using ecdl.demo.model.expression;

namespace ecdl.demo.model.word {
    public class WordTasksSerializer : FileTaskSerializer {

        public WordTasksSerializer() : base() {
        }

        protected override void AddPreconditions() {

        }

        protected override XmlAttributes GetPreconditionsAttributes() {
            var attributes = base.GetPreconditionsAttributes();
            return attributes;
        }

        protected override void AddOverrides() {
            base.AddOverrides();
            AddAttributeOverride(typeof(WordTaskDTO), "Expression", GetExpressionXmlElementAttributes());
        }

        protected override void RegisterTypes() {
            base.RegisterTypes();
            AddExpressionElementAttribute(typeof(WordBookmarkRegexExpressionDTO), "BookmarkExists");
            AddExpressionElementAttribute(typeof(ParagraphExistsExpressionDTO), "ParagraphExists");
        }

        protected override Type GetRootType() {
            return typeof(WordTaskCatalog);
        }

        public void Serialize(WordTaskCatalog taskCatalogue, TextWriter writer) {
            serializer.Serialize(writer, taskCatalogue);
        }

        public WordTaskCatalog Deserialize(StreamReader reader) {
            return (WordTaskCatalog)serializer.Deserialize(reader);
        }

        public WordTaskCatalog Deserialize(StringReader reader) {
            return (WordTaskCatalog)serializer.Deserialize(reader);
        }

    }
}
